package com.lzy.test;

import lombok.Data;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @ClassName: Demo1
 * @Description: 测试groupingBy，分组后收集某属性值
 * @Author: LiuZy
 * @Date: 2022/4/10 14:53
 * @Version: 1.0
 */
public class Demo1 {

    @Data
    public static class Inner extends Demo1 {
        private List<String> list;
    }

    public static void hello() {
        System.out.println("hello");
    }

    public static void main(String[] args) {

//        System.out.println(new Inner().list.size());
////        Map<Integer, List<String>> customerDetailMap = salesOutstockList.stream().collect(Collectors.groupingBy(WarehouseSalesOutstock::getOrgId, Collectors.mapping(WarehouseSalesOutstock::getCustomerCode, Collectors.toList())));
        List<Student> list = new ArrayList<>();
        list.add(Student.builder().classId(1).name("木丁西").build());
        list.add(Student.builder().classId(1).name("小龙女").build());
        list.add(Student.builder().classId(2).name("刘德华").build());
        list.add(Student.builder().classId(3).name("郭富城").build());
        list.add(Student.builder().classId(3).name("小姐姐").build());
        list.add(Student.builder().classId(3).name("木先生").build());
        list.add(Student.builder().classId(3).name("张学友").build());
        list.add(Student.builder().classId(3).name("张学友").build());
        list.add(Student.builder().classId(3).name("张学友").build());
        list.add(Student.builder().classId(3).name("张学友").build());
        list.add(Student.builder().classId(3).name("张学友").build());
        list.add(Student.builder().classId(3).name("张学友").build());
        list.add(Student.builder().classId(3).name("张学友").build());

        Map<Integer, List<Student>> map = list.stream().collect(Collectors.groupingBy(Student::getClassId));
        for (List<Student> value : map.values()) {
            System.out.println(value);
        }

        Iterator<Student> iterator = list.iterator();

//
//        //分组后，再收集某属性值
//        Map<Integer, List<String>> map = list.stream().collect(Collectors.groupingBy(Student::getClassId, Collectors.mapping(Student::getName, Collectors.toList())));
//        Map<Integer, List<Student>> map2 = list.stream().collect(Collectors.groupingBy(Student::getClassId));
//
//        System.out.println(map);
//        System.out.println(map2);
//
//        List<Student> l1 = list.stream().distinct().collect(Collectors.toList());
//        System.out.println(l1);
//        System.out.println(l1.size());
//
//        Iterator<Student> it = list.iterator();
//        while (it.hasNext()) {
//            Student stu = it.next();
//            System.out.println(stu);
//        }

//        List<CompletableFuture> futures = new ArrayList<>();
//
//        for (int i = 0; i < 10; i++) {
//            int a = i;
//            CompletableFuture<Void> future = CompletableFuture.runAsync(new Runnable() {
//                @Override
//                public void run() {
//                    try {
//                        if(a == 4){
//                            int a = 1/0;
//                        }
//                        System.out.println(a);
//                    } catch (Exception e) {
//                        throw new RuntimeException(e);
//                    }
//                }
//            });
//            futures.add(future);
//        }
//        CompletableFuture<Void> headerFuture = CompletableFuture.allOf(futures.toArray(new CompletableFuture[]{}));
//        headerFuture.join();
//
//        System.out.println("hhhhh");

    }

}